#!/usr/bin/env python
# _*_coding:utf-8_*_

"""
@Time :    2019/10/26 15:47
@Author:  ThinHeader
@File: serializers.py
@Software: PyCharm
"""
from rest_framework import serializers

from common.tools.money_cast import FloatToIntField
from groupshopping.models import GroupShopping, ShoppingModel


class ShoppingModelSerializer(serializers.ModelSerializer):
    """
    砍价模式序列化类
    """
    price = FloatToIntField(
        error_messages={
            'invalid': u'价格应为数字',
        }
    )

    class Meta:
        model = ShoppingModel
        fields = (
            'id',
            'info_id',
            'number',
            'price',
            'status'
        )
        read_only_fields = (
            'id',
        )


class GroupShoppingSerializer(serializers.ModelSerializer):
    """
    微砍价序列化类
    """

    class Meta:
        model = GroupShopping
        fields = (
            'id',
            'shop',
            'title',
            'start_time',
            'end_time',
            'image',
            'show_group',
            'inventory',
            'shelve',
            'music',
            'desc',
            'status',
        )
        read_only_fields = (
            'id',
            'shelve'
        )
